package com.example.q_kang.hhh.message;

import com.example.q_kang.hhh.api.JsonCallBack;
import com.hjq.toast.ToastUtils;
import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.base.BasePresenter;
import com.sskj.base.api.Constant;
import com.sskj.base.base.HttpData;
import com.sskj.base.bean.MessageListBean;
import com.example.q_kang.hhh.api.JsonConverter;

import java.util.List;

import io.reactivex.Flowable;


/**
 * @author Hey
 * Create at  2019/04/09
 */
class MessagePresenter extends BasePresenter<MessageFragment> {

    /**
     * 我的竞猜列表
     */
    public Flowable<List<MessageListBean.MessageBean>> getMessageList(int page) {
        return httpService.getMessage(page)
                .tag(this)
                .converter(new JsonConverter<HttpData<MessageListBean>>() {
                })
                .adapt(new FlowableBody<>())
                .map(listHttpData -> listHttpData.getData().getMessageList());
    }

    public void deleAllMsg() {
        httpService.deleteAllMsg()
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtils.show(body.getMsg());
                        if (body.getStatus() == Constant.OK) {
                            mView.deleteAllSuccess();
                        }
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });
    }
}
